file chooser: Avoid a crash
authorMatthias Clasen <mclasen@redhat.com>
Wed, 16 Sep 2015 14:39:19 +0000 (07:39 -0700)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 16 Sep 2015 14:41:02 +0000 (07:41 -0700)
When right-clicking in an empty folder, you should get a context
menu, not a crash. The code for positioning the popover was not
handling the eventuality of no row under the pointer. Just position
the popover right at the click location in this case.

https://bugzilla.gnome.org/show_bug.cgi?id=755021

gtk/gtkfilechooserwidget.c

index 8c25741bb9b2b922c17a5158f67a3dd36ec904c4..d286fcf08644556f9c71dd1beadca39420049353 100644 (file)
@@ -2312,18 +2312,27 @@ file_list_show_popover (GtkFileChooserWidget *impl,
 
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->browse_files_tree_view));
   list = gtk_tree_selection_get_selected_rows (selection, &model);
-  path = list->data;
-  gtk_tree_view_get_cell_area (GTK_TREE_VIEW (priv->browse_files_tree_view), path, NULL, &rect);
-  gtk_tree_view_convert_bin_window_to_widget_coords (GTK_TREE_VIEW (priv->browse_files_tree_view),
+  if (list)
+    {
+      path = list->data;
+      gtk_tree_view_get_cell_area (GTK_TREE_VIEW (priv->browse_files_tree_view), path, NULL, &rect);
+      gtk_tree_view_convert_bin_window_to_widget_coords (GTK_TREE_VIEW (priv->browse_files_tree_view),
                                                      rect.x, rect.y, &rect.x, &rect.y);
 
-  rect.x = CLAMP (x - 20, 0, gtk_widget_get_allocated_width (priv->browse_files_tree_view) - 40);
-  rect.width = 40;
+      rect.x = CLAMP (x - 20, 0, gtk_widget_get_allocated_width (priv->browse_files_tree_view) - 40);
+      rect.width = 40;
 
-  g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
+      g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
+    }
+  else
+    {
+      rect.x = x;
+      rect.y = y;
+      rect.width = 1;
+      rect.height = 1;
+    }
 
   gtk_popover_set_pointing_to (GTK_POPOVER (priv->browse_files_popover), &rect);
-
   gtk_widget_show (priv->browse_files_popover);
 }